#-----------------------------------------------------------------------------
# Name:        error.py
# Purpose:     print error messages
#
# Author:      wbauer
#
# Created:     2005/02/02
# RCS-ID:      $Id: error.py $
# Copyright:   (c) 2005
# Licence:     LGPL
#-----------------------------------------------------------------------------

# print error messages on console or in zope or wxLogError

from sys import exit
DESTCONSOLE = 'cons'
DESTWIN = 'win'
DESTZOPE = 'zope'

errors = {'WSQL001':'Warnung',
'ESQL001':'Error: Module MySQLdb not implemented in Python -> implement it',
'ESQL002':'Connection To Database Error!(MySQL not running or wrong password?)'+ 
            '\nGiven connect-Parameters: host="%s" user="%s" db="%s"!',
'ESQL003':'Connection Error: Possibly database not running?',
'ESQL004':'Table and Sql Parameter both set! Table= %s SQL= %s!',
'ESQL005':'Mastertable given, but Links missing!',
'ESQL006':'SQL-Statement wrong or wrong database Statement: %s!',
'ESQL020':'Error: CSV module not implemented in python(/site-packages)!',
'ESQL021':'Error opening table-csv-File. Control the filename!',
'ESQL022':"Don't set Sql-Atribute! Table= %s, SQL=%s !",
'ESQL023':'Error opening master-csv-file. Control the filename!',
'ESQL024':'Error: Detaillink not in table.',
'ESQL025':'Error: Masterlink not in master-table!',
'ESQL026':'Error: Sortfield not in table!',
'ESQL040':'Error: Module pgdb not implemented in Python -> implement it!',
'ESQL041':'Connection To Database Error!(Postgresql not running or wrong password?)'+
           '\nGiven connect-Parameters: host= %s,user= %s, db= %s!',

'EPAR001':"File Error: File '%s' not available! ",
'EPAR002':"Error: wrong coordinate-list of polygon '%s': %s!",
'EPAR003':"Error: Wrong origin '%s' in Parameter %s!" ,
'EPAR004':"Error: Database-type '%s' is not implemented!",
'EPAR005':"Error: masterlink or detaillink empty in %s",
'EPAR006':"Error: missing column in %s",
'EPAR007':"Error: missing header and footer in %s",
'EPAR008':"Error: Wrong Pagesize '%s'!",
'EPAR009':"Error: Wrong type for pagesequence-Parameter '%s' in layout!",
'EPAR010':"Error: Wrong type '%s' in section!",
'EPAR011':"Error: Wrong type '%s' in Field!",

'WPAR001':"Error:Unknown NodeName: %s",

'EPLA001':"Parameter '%s' not found !",
'EPLA002':"Index - Error reading from commandline for parameter '%s'",
'EPLA003':"Missing Parameter '--%s=' in commandline for Parameter %s ",
'EPLA004':"Error: Syntax in function-Parameter '%s' is invalid: %s",
'EPLA005':"Error for Parameter '%s': %s is not integer type!",
'EPLA006':"Error: key='%s' in datasource '%s' has origin='%s'(should be origin='key')",
'EPLA007':"Error: Empty user-, password- or database-Parameter in Datasource '%s'!",
'EPLA008':"Error: table- and sql-Parameter should not both be empty in Datasource '%s'!",
'EPLA009':"Error: Empty table-Parameter with non-empty master-Parameter in Datasource '%s'!",
'EPLA010':"Error: Empty name-Parameter in %s!!" ,
'EPLA011':"Error: Name '%s' is multiple used!",
'EPLA012':"Error: Section-typ '%s' should only be used once!",
'EPLA013':"Error in parameter '%s': Group with name '%s' not declared",
'EPLA014':"Error in parameter '%s': Column with name '%s' not in DB or not numeric!",
'EPLA015':"Error: Datasource '%s' missing in section '%s'!",
'EPLA016':"Error: Database-Field '%s' not included in Datasource!",
'EPLA017':"Error: Group '%s' must have a header or/and a footer section!",
'EPLA018':"Error: Datasource '%s' in header and footer not equal!",
'EPLA019':"Error: Database-Field '%s' not included in Datasource '%s'!",
'EPLA020':"Error: Parameter with name '%s' not found!",
    
'WPLA001':"Warning: for Parameter '%s': %s is not real type!" ,
'WPLA002':"Warning: Header in group '%s' is not a section!",
'WPLA003':"Warning: Footer in group '%s' is not a section!",
'WPLA004':"Warning: no length for '%s'! Length = %s assumed",
'WPLA005':"Error: key='%s' in datasource '%s' was not found in <Parameters>",
'WPLA006':"Error: Table keyname '%s' must have the columns: 'attribute','origin','value'"

}
destin = DESTCONSOLE
class WinException(Exception):
    pass

def setDestination(dest):
    global destin
    if dest in [DESTCONSOLE,DESTWIN,DESTZOPE]:
        destin = dest
    else:
        print "ERROR in destination of error-messages -Abort"
        
def errorPrint(errornumber,errortupel):
    if errors.has_key(errornumber):
            errortext = errors[errornumber]
    else:
        errortext = "Error: UNKNOWN ERROR !!!"
    
    if errortupel != None:
        outError= errortext % errortupel
    else:
        outError = errortext
    if destin == DESTCONSOLE:
        print "******************************************************"
        print outError
        print "******************************************************"
        if errornumber[0] == 'E':
            exit(1)
    elif destin == DESTWIN:
        from globals import *
        wxLogError(outError)
        raise WinException
    elif destin == DESTZOPE:
            # zope error message
            pass
    else:
        print "******************************************************"
        print outError
        print "******************************************************"

    

